/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package source;

import java.io.PrintWriter;
import java.io.FileNotFoundException;
import static source.mpMain.bConsole;

/**
 *
 * @author admin
 */
public class mpLog {
	private static PrintWriter	fileLog;
	private static mpGUI		jWindow;
			
	public static void __init() {
		if (!bConsole) {
			jWindow = mpMain.getWindow();
		}
		try {
			fileLog = new PrintWriter("debug.log");
		} catch (FileNotFoundException ex) {
			if(bConsole) {
				System.out.println("dbglog: \"debug.log\" read failure..");
			} else {
				jWindow.add2Log("dbglog: \"debug.log\" read failure..");
			}
		}
	}
	public static void __destroy() {
		fileLog.close();
	}
	public static void writeLog(Object oObj) {
		fileLog.println(oObj.toString());
		fileLog.flush();
	}
	public static void dbgLog(Object oObj) {
		if(mpMain.bDebug) {
			String sLog = "dbglog: " + oObj.toString();
			fileLog.println(sLog);
			if(bConsole) {
				System.out.println(sLog);
			} else {
				jWindow.add2Log(sLog);
			}
		}
	}
	public static void objLog(Object oClassObject, Object oObj) {
		String sLog = oClassObject.getClass().getSimpleName().substring(2, 8) + ": " + oObj.toString();
		writeLog(sLog);
		if(bConsole) {
			System.out.println(sLog);
		} else {
			jWindow.add2Log(sLog);
		}
	}
	public static void srvLog(Object oClassObject, Object oObj) {
		String sLog = oClassObject.getClass().getSimpleName().substring(2, 8) + ": " + oObj.toString();
		writeLog(sLog);
		if(bConsole) {
			System.out.println(sLog);
		} else {
			jWindow.add2Log(sLog);
		}
	}
	public static void syncLog(Object oObj) {
		String sLog = "__sync: " + oObj.toString();
		writeLog(sLog);
		if(bConsole) {
			System.out.println(sLog);
		} else {
			jWindow.add2Log(sLog);
		}
	}
}
